from dataclasses import dataclass
from enum import Enum

import orjson as json


class ObjectType(Enum):
    ObjectType_Man = 0
    ObjectType_Man_Blue_Marine_ShooterM14 = 1
    ObjectType_Man_Blue_Marine_ShooterM16 = 2
    ObjectType_Vehicle = 100
    ObjectType_Vehicle_Blue_Marine_LAVAT = 101
    ObjectType_UnmannedVehicle = 200
    ObjectType_UnmannedVehicle_Red_BiGua = 250
    ObjectType_UnmannedVehicle_Red_BaZhaoYu = 251
    ObjectType_UnmannedVehicle_Red_AirDefence = 252
    ObjectType_UnmannedVehicle_Red_ZCDY = 253
    ObjectType_AirCraft = 300
    ObjectType_UAV = 400
    ObjectType_UAV_Red_DR200 = 450
    ObjectType_UAV_Red_DR400 = 451
    ObjectType_UAV_Red_FSS = 452
    ObjectType_UAV_Bluw_thd = 453
    ObjectType_Obstacles = 500
    ObjectType_Obstacles_BalloonRed = 501
    ObjectType_Obstacles_BalloonGreen = 502
    ObjectType_Obstacles_BalloonBlue = 503
    ObjectType_Obstacles_BalloonYellow = 504
    ObjectType_Obstacles_board = 505
    ObjectType_Obstacles_telPole = 506


@dataclass
class Position3D:
    lon: float = 0.0
    lat: float = 0.0
    altitude: float = 0.0


@dataclass
class RotationAngles:
    yaw: float = 0.0
    pitch: float = 0.0
    roll: float = 0.0


@dataclass
class Vector3D:
    x: float = 0.0
    y: float = 0.0
    z: float = 0.0


@dataclass
class DefendAreaInfo:
    topBound: float
    bottomBound: float
    leftBound: float
    rightBound: float


@dataclass
class BoundingBoxInfo:
    centerPoint: Vector3D
    """Center of the bounding box in world coordinate system (x, y, z)"""

    leftBottom: Vector3D
    """Relative position of the bottom-left corner of the bounding box to the center point (x, y, z)"""

    rightTop: Vector3D
    """Relative position of the top-right corner of the bounding box to the center point (x, y, z)"""


@dataclass
class AmmoInfo:
    ammoType: str
    ammoNum: int


@dataclass
class AmmoCountInfo:
    ammoType: str
    count: int


@dataclass
class ObjectInfo:
    objectName: str
    objectCamp: int
    objectType: ObjectType
    objectPosition: Position3D
    objectOrientation: RotationAngles
    lifeValue: float
    ammoInfo: str
    objectVelocity: Vector3D
    acceleration: Vector3D
    perceptionRange: float
    attackRange: float
    boundingBox: BoundingBoxInfo

    def __post_init__(self):
        try:
            self.ammos = [AmmoInfo(**x) for x in json.loads(self.ammoInfo)]
        except:
            self.ammos = []


@dataclass
class ManeuveringInfo:
    pos: Position3D
    velocityExpected: Vector3D
    dir: float
